package com.sgb.kjwl.view.widget;

import android.content.Context;
import androidx.databinding.DataBindingUtil;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.MapInfoWindowBinding;
import com.sgb.kjwl.model.entity.transport.MapCarsSourcesEntity;
import com.sgb.kjwl.model.entity.transport.MapSourcesEntity;

public class MapSourcesInfoWindow extends LinearLayout {

    protected Context mContext;
    protected MapInfoWindowBinding viewBinding;
    private MapCarsSourcesEntity supplierEntity3;
    private MapSourcesEntity mapSourcesEntity;

    public MapSourcesInfoWindow(Context context) {
        this(context, null);
    }

    public MapSourcesInfoWindow(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MapSourcesInfoWindow(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public MapSourcesInfoWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }

    private void initView() {
        viewBinding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.map_info_window, this, true);
    }

    public void setData(MapCarsSourcesEntity supplierEntity3) {
        this.supplierEntity3 = supplierEntity3;
        viewBinding.titleView.setText(supplierEntity3.getName());
//        viewBinding.distanceView.setText(supplierEntity3.getCarNumber());
//        viewBinding.contentView.setText("主营：" + supplierEntity3.getCityName());

        RequestOptions options = new RequestOptions()
                .dontAnimate()
                .placeholder(R.drawable.null_img_list)
                .error(R.drawable.null_img_list)
                .centerCrop();
        Glide.with(mContext)
                .load(supplierEntity3.getCarImage())
                .apply(options)
                .into(viewBinding.imgView);
    }

    public void setData(MapSourcesEntity supplierEntity3) {
        this.mapSourcesEntity = supplierEntity3;
        viewBinding.titleView.setText(supplierEntity3.getGoodsTypeName());
//        viewBinding.distanceView.setText(supplierEntity3.getDistance());
//        viewBinding.contentView.setText("主营：" + supplierEntity3.getContent());

        RequestOptions options = new RequestOptions()
                .dontAnimate()
                .placeholder(R.drawable.null_img_list)
                .error(R.drawable.null_img_list)
                .centerCrop();
//        Glide.with(mContext)
//                .load(supplierEntity3.getImgUrl())
//                .apply(options)
//                .into(viewBinding.imgView);
    }
}
